package com.yz.group9.med_booking.controlle;


import com.yz.group9.med_booking.entity.Department;
import com.yz.group9.med_booking.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List; 

@CrossOrigin//允许跨域请求
//接收请求，返回结果
@RestController//标记当前类是一个控制器类 返回结果为JSON数据结构
@RequestMapping("/department")//统一的前缀，前端访问 /department开头的接口
public class DepartmentController {


    //找Service 要数据
    @Autowired//注入Service
    private DepartmentService departmentService;
    //api：application+program+interface  应用程序编程接口
    @GetMapping//对应的事Get请求，访问“/department”路径时触发此api
    public List<Department> departmentList(){
        return departmentService.listAllDepartment();
    }
    @PostMapping("/updateStatus")
    public boolean updateStatus(@RequestBody Department department){
        return departmentService.updateById(department);
    }
    @DeleteMapping("/delete/{id}")
    public boolean deleteById(@PathVariable Long id){
        return departmentService.removeById(id);
    }
    @PostMapping("/add")
    public boolean add(@RequestBody Department department){
        return departmentService.save(department);
    }


}
